#include"../ser/server.hpp"


void OnClosed(const PtrConnection &con)
{
    // std::cout<<"连接断开"<<std::endl;
    LOG_DEBUG("Connection closed:%p",con.get());
}

void OnMessage(const PtrConnection &con,Buffer *buf)
{
   LOG_DEBUG("recv data:%s",buf->current_read_pos());
   buf->move_read_pos(buf->readable_size());
   std::string str="hello world";
   con->Send(str.c_str(),str.size());
//    con->Shutdown();
}

void OnConnected(const PtrConnection &con)
{
    // std::cout<<"连接成功"<<std::endl;
    LOG_DEBUG("New connection:%p",con.get());
}

int main()
{
    TcpServer server(8080);
    server.SetThreadNum(2);
    server.EnableInactiveRelease(10);
    server.SetConnectedCallback(OnConnected);
    server.SetMessageCallback(OnMessage);
    server.SetCloseCallback(OnClosed);
    server.Start();
    return 0;
}

